package com.kingyea.gradle.jsch;

import java.io.File;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.apache.commons.io.FileUtils;
import org.gradle.api.tasks.TaskAction;

public class MyTask {
	private List<Action> actions = new CopyOnWriteArrayList<>();
	
	public void copy(final String source, final String dest) throws Exception {
		this.actions.add(new Action() {
			@Override
			public void execute() throws Exception {
				FileUtils.copyFile(new File(source), new File(dest));
			}
		});
	}
	
	public void copyDependencies() {
		this.actions.add(new Action() {
			@Override
			public void execute() throws Exception {
				File dir = new File("H:\\sourceDir");
				for(File file : dir.listFiles()) {
					copy(file.getAbsolutePath(), "H:\\destDir\\"+file.getName());
				}
			}
		});
	}
	
	@TaskAction
	public void execute() throws Exception {
		for(Action action : this.actions) {
			action.execute();
		}
	}
	
	public static interface Action {
		void execute() throws Exception;
	}
	
	
	public static void main(String[] args) throws Exception {
		MyTask bug = new MyTask();
		bug.copyDependencies();
		bug.execute();
	}
}
